package com.yitao.cms.controller.user.cmsUser;
import com.skipper.base.bean.DataOutput;
import com.skipper.base.bean.PagedInput;
import com.skipper.base.bean.PagedOutput;
import com.yitao.cms.config.aopLog.LogAnnotation;
import com.yitao.cms.dto.operationUser.OperationRoleDto;
import com.yitao.cms.service.user.cmsUser.OperationRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;



@Api(value = "role", description = "角色模块")
@RestController
@RequestMapping("/role")
public class OperationRoleController {
    @Autowired
    private OperationRoleService roleService;

    @ApiOperation("角色列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public DataOutput roleList(
            @ApiParam(value = "状态TRUE:有效,FALSE:无效") @RequestParam(value = "state", required = false) Boolean state
    ) {
        return roleService.findAllRole(state);
    }
    @ApiOperation("角色列表(分页)")
    @RequestMapping(value = "/rolePageList", method = RequestMethod.POST)
    public PagedOutput<OperationRoleDto> rolePageList(
            @ApiParam(value = "状态TRUE:有效,FALSE:无效") @RequestParam(value = "state", required = false) Boolean state,
            @ApiParam(value = "分页参数，表示当前页", required = true, defaultValue = "1") @RequestParam(value = "pageNo") Integer pageNo,
            @ApiParam(value = "分页参数，表示每页显示多少条记录", required = true, defaultValue = "10") @RequestParam(value = "pageSize") Integer pageSize
    ) {
        PagedInput pagedInput = new PagedInput(pageSize,pageNo);
        return roleService.rolePageList(state,pagedInput);
    }

    @ApiOperation("角色添加/修改")
    @LogAnnotation(targetType = "role-saveRole", remark = "角色添加/修改")
    @RequestMapping(value = "/saveRole", method = RequestMethod.POST)
    public DataOutput roleAdd(@RequestBody OperationRoleDto roleDto, HttpServletRequest request) {
        return roleService.saveRole(roleDto,request);
    }
    @ApiOperation("查看角色详情")
    @RequestMapping(value = "/findRoleById", method = RequestMethod.POST)
    public DataOutput findRoleById(Long roleId) {
        return roleService.findRoleById(roleId);
    }

    @ApiOperation("启用/禁用角色")
    @LogAnnotation(targetType = "role-updateRoleStatus", remark = "启用/禁用角色")
    @RequestMapping(value = "/updateRoleStatus", method = RequestMethod.POST)
    public DataOutput updateRoleStatus(
                                       @ApiParam(value = "角色ID") @RequestParam(value = "roleId", required = false) Long roleId,
                                       @ApiParam(value = "状态TRUE:有效,FALSE:无效") @RequestParam(value = "state", required = false) Boolean state
    ) {
        return roleService.updateRoleStatus(roleId,state);
    }


   /*

    @ApiOperation("给角色绑定资源")
     @RequestMapping(value = "/addRolePermission", method = RequestMethod.POST)
     public  BaseOutput addRolePermission(String jsonStr) {
         rolePermissionService.addRolePermission(jsonStr);
         return new BaseOutput("绑定成功");
     }



   */
}
